package com.thread.sync.sync02;

public class ObjectLock {
    public void method1() {
        synchronized (this) {  //对象锁
            try {
                System.out.println("method---1");
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public void method2() {
        synchronized (ObjectLock.class) { //类锁
            try {
                System.out.println("method---2");
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

    private Object lock = new Object();

    public void method3() {
        synchronized (lock) {  //任何对象锁
            try {
                System.out.println("method---3");
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

}
